package com.bitstu.QRcode;

import com.google.zxing.*;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;

public class reader {
    public static void main(String[] args) {
        MultiFormatReader multiFormatReader=new MultiFormatReader();
        File file=new File("E:/code/img.png");
        BufferedImage image= null;
        try {
            image = ImageIO.read(file);
            BinaryBitmap binaryBitmap=new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));
            HashMap hints=new HashMap();
            hints.put(EncodeHintType.CHARACTER_SET,"utf-8");
            try {
                Result result=multiFormatReader.decode(binaryBitmap,hints);
                System.out.println(result.toString());
            } catch (NotFoundException e) {
                e.printStackTrace();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
